import { myEnv } from '@/myEnv';
import { mergeRequest } from '@/utils';
import { MyMessageList_Web, MyMessageList_Res } from '@/pages/_server/_class/MyMessage/MyMessageList';
type params = {
    pageIndex: number;
    haveRead?: 0 | 1 | null;
};
/** 获得消息列表 */
export const apiGetMessageList = async (params: params) => {
    const response1: MyResponse<MyMessageList_Res[]> = await sendRequest(params);
    if (!response1) return;
    const webData = response1.data.map((item) => {
        return new MyMessageList_Web().immit_response(item);
    });
    const resonlse2: MyResponse<MyMessageList_Web[]> = { ...response1, data: webData };
    return resonlse2;
};

const sendRequest = async (params: params) => {
    let response1: MyResponse<MyMessageList_Res[]>;
    if (myEnv.IS_ON_LINE) {
        response1 = await mergeRequest({
            url: `/user/message`,
            method: 'GET',
            data:params
        });
    } else {
        response1 = {
            code: '200',
            message: 'ok',
            data: [
                {
                    id: '1',
                    haveRead: 0,
                    content: '这是系统消息',
                    type: 'sys',
                },
                {
                    id: '2',
                    haveRead: 1,
                    content: '这是订单统消息单统消息单统消息单统消息',
                    type: 'order',
                },
                {
                    id: '3',
                    haveRead: 0,
                    content: '这是交互交互消息',
                    type: 'interact',
                },
                {
                    id: '4',
                    haveRead: 0,
                    content: '这是系统消息',
                    type: 'sys',
                },
                {
                    id: '5',
                    haveRead: 1,
                    content: '这是订单统消息单统消息单统消息单统消息',
                    type: 'order',
                },
                {
                    id: '6',
                    haveRead: 0,
                    content: '这是交互交互消息',
                    type: 'interact',
                },
                {
                    id: '7',
                    haveRead: 0,
                    content: '这是系统消息',
                    type: 'sys',
                },
                {
                    id: '8',
                    haveRead: 1,
                    content: '这是订单统消息单统消息单统消息单统消息',
                    type: 'order',
                },
                {
                    id: '9',
                    haveRead: 0,
                    content: '这是交互交互消息',
                    type: 'interact',
                },
            ],
        };
    }
    return response1;
};
